package com.zle.controller.book;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class BookController extends BookAbstractController{
	/**
	 * 跳转至所有书籍页面
	 * @return
	 */
	@RequestMapping("/book_show_all.action")
	public String bookShwoAll(){
		return "/book/book_shwo_all";
	}
	/**
	 * 跳转至个人订阅页面
	 * @return
	 */
	@RequestMapping("/book_shwo_my.action")
	public String bookShowMy(){
		return "/book/book_shwo_my";
	}
	/**
	 * 查询所有书籍
	 * @param bname
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/query_all_books.action")
	@ResponseBody
	public Map<String,Object> queryAllBooks(@RequestParam(required=false)String bname,Integer page,Integer rows){
		return getBookService().queryAllBooks(bname, page, rows,getUser());
	}
	/**
	 * 个人订阅查询
	 * @param bname
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/query_my_books.action")
	@ResponseBody
	public Map<String,Object> queryMyBooks(@RequestParam(required=false)String bname,Integer page,Integer rows){
		return getBookService().queryMyBooks(bname, page, rows,getUser());
	}
	@RequestMapping("/order_one.action")
	@ResponseBody
	public Map<String,Object> orderOne(Integer id){
		boolean tag = getBookService().isOrdered(getUser(), id);
		if(tag){
			getBookService().orderBook(getUser(), id);
			viewData.put("result", true);
		}else{
			viewData.put("result", false);
		}
		return viewData;
	}
	/**
	 * 从书库订阅
	 * @param id
	 * @return
	 */
	@RequestMapping("/order_old.action")
	@ResponseBody
	public Map<String,Object> order(String ids){
		getBookService().orderBook(getUser(), ids);
		viewData.put("result", true);
		return viewData;
	}
	/**
	* 自定义订阅
	* @param id
	* @return
	*/
	@RequestMapping("/order_new.action")
	@ResponseBody
	public Map<String,Object> orderNew(String newbookname,String url,Integer webId){
		getBookService().orderNewBook(getUser(),newbookname,url,webId);
		viewData.put("result", true);
		return viewData;
	}
	/**
	 * 取消订阅
	 * @param id
	 * @return
	 */
	@RequestMapping("/cancel_order.action")
	@ResponseBody
	public Map<String ,Object> cancelOrder(Integer id){
		
		getBookService().cancelOrderBook(getUser(), id);
		viewData.put("result", true);
		return viewData;
	}
	/**
	 * 从已收录书籍中订阅
	 * @param id
	 * @return
	 */
	@RequestMapping("/order.action")
	@ResponseBody
	public Map<String ,Object> orderFromAll(Integer id){
		getBookService().orderBook(getUser(), id);
		viewData.put("result", true);
		return viewData;
	}
	
	
	
	
	
	
}
